package com.lagou.mr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.File;
import java.io.IOException;

public class SortDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(SortMapper.class);
        job.setJobName("mysort");
        job.setMapperClass(SortMapper.class);   //输入数据方法
        job.setReducerClass(SortReducer.class);//计算结果

        job.setOutputKeyClass(LongWritable.class);
        job.setOutputValueClass(LongWritable.class);

        //mysort 包含三个sorfile.txt文件，结果输出到outsort
        FileInputFormat.addInputPath(job,new Path("file:///f:/mysort"));
        FileOutputFormat.setOutputPath(job,new Path("file:///f:/outsort"));
        System.exit(job.waitForCompletion(true)?0:1);
    }
}
